<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      ul {
        width: 600px;
        display: flex;
        justify-content: space-around;
        border: 1px red solid;
        margin: auto;
        flex-wrap: wrap;
      }
      li {
        list-style-type: none;
        border: 1px #000 solid;
        width: 120px;
        height: 120px;
        text-align: center;
        line-height: 120px;
        margin: 10px;
      }
      img {
        width: 100px;
        height: 100px;
        opacity: 0.5;
        cursor: crosshair;
      }
    </style>
  </head>
  <body>
    <ul>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
      <li>
        <img src="./1.jpg" alt="" />
      </li>
    </ul>
  </body>
</html>
<script>
  var lis = document.getElementsByTagName("li");
  var imgs = document.getElementsByTagName("img");

  for (let i in lis) {
    lis[i].onmouseover = function () {
      imgs[i].style.opacity = 1;
    };

    lis[i].onmouseout = function () {
      imgs[i].style.opacity = 0.5;
    };
  }
</script>
